/**
 *    @file       threadcore.cpp
 *
 *    @brief      
 *    @details
 *
 *    @version    1.0
 *    @date       12/19/2012 03:52:14 PM
 *
 *    @author     Theophilus (), wangtf418@gmail.com
 */
#include <sys/types.h>
#include <unistd.h>
#include <pthread.h>
#include "threadcore.h"

threadcore::threadcore()
	: m_runflag(0), m_processid(0), m_threadid(0)
{

}

threadcore::~threadcore()
{

}

bf_int_t threadcore::start()
{
	if (m_runflag)
	{
		return BF_ERROR;
	}

	int ret = init();
	if (ret != BF_OK)
	{
		return BF_ERROR;
	}

	m_processid = getpid();
	m_runflag = 1;
	ret = pthread_create(&m_threadid, NULL, thread_entry, this);
	if (ret != 0)
	{
		m_runflag = 0;
		return BF_ERROR;
	}
	return BF_OK;
}

void threadcore::stop()
{
	m_runflag = 0;
}

void* threadcore::thread_entry(void *arg)
{
	threadcore *thread = (threadcore*)arg;
	thread->run();
	return NULL;
}




